<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Goods extends FOX_Controller {

	function __construct ()
	{
		parent::__construct();
		$this->load->model('good_m');
		$this->load->model('shop_m');
		$this->load->model('api_good_m');
		$this->load->model('areas_m');
		$this->load->model('category_m');
		$this->load->model('attachs_m');
	}
	public function flist(){
		$category_tid = $this->uri->segment(3);
		if(!is_numeric($category_tid)){
			exit();
		}
		$user_id = $this->session->userdata('user_id');
		$data['category_info'] = $this->category_m->get_category_by_id($category_tid);
		//$listone = $this->category_m->get_category_by_id($category_tid);
		$data['total'] = $this->good_m->count_goods_list_by_catagory_id($category_tid);
		$data['good_list'] = $this->good_m->get_goods_list_by_catagory_id(0,$this->config->item('page_list_home'),$category_tid);
		if($data['good_list']){
			foreach ($data['good_list'] as $k => $v) {
				$data['good_list'][$k]['count_orders'] = $this->api_good_m->count_shop_orders_count_by_good_id($v['good_id']);
				//获取图片
				$pic_lists = $this->attachs_m->get_one_attachs_by($v['good_cover']);
				if($pic_lists){
					$data['good_list'][$k]['good_cover'] = get_jianlou_image($pic_lists['file_location'],$pic_lists['file_name'],"big");
				}else{
					$data['good_list'][$k]['good_cover'] = base_url('uploads/goods/nopic.jpg');
				}
			}			
		}
		if($user_id){
			$arr['user_id'] = $user_id;
			$arr['web_category'] = $data['category_info']['all_category'];
			$arr['category_tid'] = $category_tid;
			$arr['catogory_time'] = time();
			$arr['catogory_type'] = 0;
			$isfavorites = $this->good_m->is_favorites($user_id,$category_tid);
			if($isfavorites){
				$result = $this->good_m->updates_user_categorys_catogory_view($isfavorites['category_id']);
			}else{
				$result = $this->good_m->add_user_categorys($arr);
			}
		}
		$data['category_tid'] = $category_tid;
		$this->load->view('product_class_list',$data);
	}
	
}
